//遮罩
app.directive('sqmask',function(){
	return {
		controller:function($scope){
			//ui初始化
			this.resizeScope=function(){
				$scope.$apply(function(){
					$scope.uiInit();
				})
			}
		},
		link:function(scope,ele,attrs,ctrl){
			ele.bind('click',function(e){
				//清除遮罩里的全部内容
				if(angular.element(e.target).hasClass('sq-mask'))
				{
					ele.html('');
					ctrl.resizeScope()
				}
			});
		}
	}
})


//防微信朋友圈气泡对话框（点赞/评论）
app.directive('sqchat',function($compile){
	return {
		template:'<i class="iconfont wechat" ng-click="showOrhide()">&#xe60a;</i>'  
					+'<div><div class="chatbox">'
					+'<a ng-click="addOrdelPra()" class="wechat {{heartAni}}">'
					+'<i class="iconfont">&#xe60b;</i>'
					+'{{ct.selfPraise==0?"赞":"取消"}}</a>'
					+'<a ng-click="showChat()" class="wechat">'
					+'<i class="iconfont">&#xe60f;</i>'
					+'评论</a>'
					+'</div></div>',
		controller:function($scope,$http){
			$scope.ct.isOpenTool='sq-hide';
			$scope.heartAni='';
			//评论
			$scope.showChat=function(){
				$scope.type="评论";
				$scope.isTie=false;			
//				$scope.uiObj.pageloadingCtrl=false;
				$scope.uiObj.layerloadingCtrl=true;
				$http.get(resUrl+'wx_api/Module/community/views/chatview.html'+version).success(function(response){
					var mask=document.getElementsByClassName('sq-mask');
					//重新编译 传入当前分支的$scope
					var el=$compile(response)($scope);
					angular.element(mask).html(el);
					$scope.sqMask.isshow='sq-active';
					$scope.ct.isOpenTool='sq-hide';
					$scope.callSuccessHttp();	
				});
			}
			//点赞or取消
			$scope.addOrdelPra=function(){
				var heartAnimate=function(){
					$scope.heartAni='heartActive';
					setTimeout(function(){
						$scope.heartAni='';
						var method;
						var index=$scope.$index;
						var _sid=$scope.ct.sid;
						if($scope.ct.selfPraise==0)
						{
							method='addPraise'
						}
						else if($scope.ct.selfPraise==1)
						{
							method='deletedPraise'
						}
						var _link=buildUrl('json','community',method,{
							qid:document.getElementById('qid').value,
							sId:_sid,
							uId:document.getElementById('uid').value
						})
						console.log(_link);
//						$scope.uiObj.pageloadingCtrl=false;
						$http.get(_link).success(function(data){
							
							console.log(data);
							if(data.code==0)
							{
								$scope.pageUi.updateListByPraise(index,data.self);
								$scope.ct.isOpenTool='sq-hide';

								
							}
							
							$scope.callSuccessHttp();
							
						});
						
					},200);
				}()
			}
			//开关对话框
			$scope.showOrhide=function(){
					//首先全部关闭
					for(var i=0;i<$scope.data.content.length;i++)
					{
						if($scope.$index!=i)
						{
							$scope.data.content[i].isOpenTool='sq-hide';
						}	
					}
					
					if($scope.ct.isOpenTool=='sq-hide')
					{
						$scope.ct.isOpenTool='sq-active';
					}
					else
					{
						$scope.ct.isOpenTool='sq-hide';
					}
				
			}
			$scope.hideAllwechat=function(){
				   //全部关闭
				    console.log($scope.data.content);
					for(var i=0;i<$scope.data.content.length;i++)
					{
					
						$scope.data.content[i].isOpenTool='sq-hide';
					
					}
				
			}
			$scope.closeChat=function(){
				$scope.uiInit();
				angular.element(document.getElementsByClassName('sq-mask')).html('');
			}
		},
		link:function(s,e,a,c){
				var doc=angular.element(document.getElementsByTagName("body")[0]);
				doc.unbind('touchend click');
				doc.on('touchend click',function(e){
					e=angular.element(e.target);
					
					if(!e.hasClass('wechat'))
					{
						
						s.$apply(function(){
							s.hideAllwechat()
						})
					}
				})
		}
	}
});
//回复别人的评论
app.directive('sqReply',function($compile){
	return {
		controller:function($scope,$http){
			var _this=this;
			//评论
			this.showChat=function(){
				console.log($scope);
				$scope.placeholder="回复"+($scope.cml.nickname!=null?$scope.cml.nickname:"匿名");
				$scope.type="回复";
//				$scope.uiObj.pageloadingCtrl=false;
				$scope.uiObj.layerloadingCtrl=true;
				$http.get(resUrl+'wx_api/Module/community/views/chatview.html'+version).success(function(response){
					var mask=document.getElementsByClassName('sq-mask');
					//重新编译 传入当前分支的$scope
					var el=$compile(response)($scope);
					angular.element(mask).html(el);
					$scope.sqMask.isshow='sq-active';
					$scope.ct.isOpenTool='sq-hide';
					$scope.callSuccessHttp();
				});
			}
			$scope.showOrdel=function(){
				var myuid=document.getElementById('uid').value;
				
				if($scope.cml.uId!=myuid)
				{
					_this.showChat();
				}
				else
				{
					console.log($scope);
					layer.open({
						style:'width:260px;text-align:center;',
						content:'<div style="height:60px;line-height:60px;font-size: 16px;color:#333;">是否删除这条回复？</div>',
						btn:['确定','取消'],
						shadeClose:false,
						yes: function(){
//					        $scope.uiObj.pageloadingCtrl=false;
							$scope.uiObj.layerloadingCtrl=true;
							$scope.$apply();
							var _link=buildUrl('json','community','deletedComment',{
								id:$scope.cml.id,
								sId:$scope.cml.sId
							})
							$http.get(_link).success(function(response){
								console.log(response);
								$scope.pageUi.updateList($scope.$parent.$parent.$index);
							});
					    }, no: function(){
					        
					    }
					});
				}
			}
		},
		link:function(s,e,a,c){
			e.on('touchstart',function(){
				e.addClass('touch')
			})
			e.on('touchend touchmove',function(){
				e.removeClass('touch')
			})
		}
	}
})
//右上角更多菜单-视图
app.directive('sqmore',function($compile){
	var template='<div ng-if="page.topOpen" class="sq-morebox {{sqMore.isshow}}"><ul>'
			+'<li ng-click="showComViews()"><i class="iconfont">&#xe608;</i>发帖</li>'
			+'</ul></div>';
	return {
		replace:true,
		template:template,
		controller:function($scope,$http){
			$scope.showComViews=function(){
				$scope.type="发表";
				$scope.isTie=true;
//				$scope.uiObj.pageloadingCtrl=false;
				$scope.uiObj.layerloadingCtrl=true;
				$http.get(resUrl+'wx_api/Module/community/views/chatview.html'+version).success(function(response){
					var mask=document.getElementById('tie')
					//重新编译 传入当前分支的$scope
					var el=$compile(response)($scope);
					angular.element(mask).html(el);
					$scope.callSuccessHttp();
					callback();
				});
				
				var callback=function(){
					$scope.sqCom.isshow='active';
					$scope.uiInit();
					setTimeout(function(){
						$scope.uiObj.isactive='sq-hide';
						$scope.$apply();
					},300)
				}
				
			}
			$scope.hideComViews=function(){
				
				$scope.uiObj.isactive='active';
				$scope.sqCom.isshow='sq-hide';
				setTimeout(function(){
					$scope.isTie=false;
					angular.element(document.getElementById('tie')).html('');
					$scope.$apply();
				});
			}
		}
	}
})
//右上角更多菜单-逻辑
app.directive('sqmorectrl',function(){
	return {
		require:'sqmorectrl',
		controller:function($scope){
			this.showOrhide=function(ele){
				
				var height;
				if($scope.sqMore.isshow=='sq-hide')
				{
					$scope.sqMore.isshow='sq-active';

				}
				else
				{
					$scope.sqMore.isshow='sq-hide';
									
				}
			}
		},
		link:function(scope,ele,attrs,ctrl){
			var _this=this;
			ele.bind('click',function(){
				scope.$apply(ctrl.showOrhide(ele));
			})
		}
	}
})
//左上角侧边栏
app.directive('sqsidectrl',function(){
	return {
		require:'sqsidectrl',
		controller:function($scope){
			console.log('-----------');
			console.log($scope);
			this.showOrhide=function(ele){
				var height;
				if($scope.sqSide.isshow=='sq-hide')
				{
//					$scope.uiObj.pageloadingCtrl=true;
					$scope.sqSide.isshow='sq-active';

				}
				else
				{
					$scope.sqSide.isshow='sq-hide';
									
				}
				$scope.sqMask.isshow=$scope.sqSide.isshow;
				
			}
		},
		link:function(scope,ele,attrs,ctrl){
			ele.bind('click',function(){
				
				scope.$apply(ctrl.showOrhide(ele));
			})
		}
	}
})

//删除帖子 文章 广告
app.directive('sqDeleted',function(){
	return {
		controller:function($scope,$http){
			$scope.deleted=function(){
				console.log()
				layer.open({
						style:'width:260px;text-align:center;',
						content:'<div style="height:60px;line-height:60px;font-size: 16px;color:#333;">是否删除这条帖子？</div>',						
						btn:['确定','取消'],
						shadeClose:false,
						yes: function(){
//					        $scope.uiObj.pageloadingCtrl=false;
							$scope.uiObj.layerloadingCtrl=true;
							$scope.$apply();
							var _link=buildUrl('json','community','deleted',{
								id:$scope.ct.id
							})
							
							$http.get(_link).success(function(response){
								console.log(response);
								layer.open({
									content:'删除成功!'
								})
								location.reload();
							});
					    }, no: function(){
					        
					    }
					});
			}
		}
	}
})
//置顶
app.directive('topopt',function(){
	return {
		controller:function($scope,$http){
			var _sid='',
				index=$scope.$index;
			if(typeof($scope.ct)=="undefined")
			{
				_sid=$scope.cl.sid
			}
			else
			{
				_sid=$scope.ct.sid
			}
			this.putOrcanceltop=function(method,text){
				layer.open({
						style:'width:260px;text-align:center;',
						content:'<div style="height:60px;line-height:60px;font-size: 16px;color:#333;">是否'+text+'置顶？</div>',						
						btn:['确定','取消'],
						shadeClose:false,
						yes: function(){
//					        $scope.uiObj.pageloadingCtrl=false;
							$scope.uiObj.layerloadingCtrl=true;
							$scope.$apply();
							var _link=buildUrl('json','community',method,{
								qid:document.getElementById('qid').value,
								sid:_sid,
							})
							console.log(_link);
							$http.get(_link).success(function(data){
//								
//								if($scope.ct.type==0||$scope.ct.type==2)
//								{
//									if($scope.ct.isTop!=null)
//									{
//										$scope.pageUi.isTopCount--;
//									}
//									else
//									{
//										$scope.pageUi.isTopCount++;
//									}
//									
//								}
								
								if(data.code==0)
								{
									location.reload();
								}
								
								
							});
					    }, no: function(){
					        
					    }
					});
					
					
				
			}
		},
		link:function(s,e,a,c){
			
			e.on('click',function(){
//				if(s.uiObj.pageloadingCtrl)
//				{
					if(e.hasClass('putTop'))
					{
						c.putOrcanceltop('setTop','确认');
					}
					else if(e.hasClass('cancelTop'))
					{
						c.putOrcanceltop('cancelTop','取消');
					}
					
//				}
				
			})
		}
	}
})
app.directive('sqShowImg',function(){
	return {
		controller:function($scope,$http){
			$scope.showImgsWx=function(){
				console.log($scope);
				wx_share.showImg($scope.ct.picUrl1,$scope.pic);
			}
		},
		link:function(){
			
		}
	}
})
//切换表情 
app.directive('sqTabs',["$rootScope",function($rootScope){
	return {
		restrict:'C',
		controller:function(){
			
		},
		link:function(s,e,a,c){
			
			e.find('li a').on('click',function(e){
					e.preventDefault()
					angular.element(this).tab('show');	
					$rootScope.updateSwiper();
			})
		}
	}
}]);
app.directive('cashTab',["$rootScope",function($rootScope){
	return {
		controller:function(){
			
		},
		link:function(s,e,a,c){
			if(s.$last)
			{
				e.parent().find('a').on('click',function(e){
					e.preventDefault()
					angular.element(this).tab('show');	
				})
			}
			
		}
	}
}]);
//swiper 插件 
app.directive('swiperDirective',["$rootScope",function($rootScope){
	return {
		controller:function(){
			this.ready=function(){
				$rootScope.initSwiper('.swiper-container');
			}
		},
		link:function(s,e,a,c){
		}
	}
}]);
app.directive('swiperSlide',function(){
	return {
        restrict: "A",
        require: "^swiperDirective",
        link: function(s,e,a,c) {
            if(s.$last) {
                c.ready();
            }
        }
    }
})
app.directive('sqWximgs',function(){
	return {
		controller:function($scope,$http){
			this.remove=function(){
				$scope.wxImgs.imgs.splice($scope.$index,1);
				$scope.wxImgs.upload=true;
			}
		},
		link:function(s,e,a,c){
			e.on('click',function(){
				c.remove();
				e.parent().remove();
			})
		}
	}
})
//发起评论or帖子
app.directive('sqMychat',function(){
	return {
		restrict:'C',
		controller:function($scope,$http){
			console.log($scope);
			$scope.imgs={
					paths:''
			}
			var width=document.body.clientWidth;
			if(width>=375)
			{
				$scope.chatsize="big";
			}
			else
			{
				$scope.chatsize="small";
			}
			$scope.postComment=function(){
				var replyid='';
				if($scope.isTie)
				{
					//发帖
					var _link=buildUrl('json','community','post',{
						qid:document.getElementById('qid').value,
						uid:document.getElementById('uid').value,
						content:$scope._comment,
						picUrl:$scope.imgs.paths
					})
//					alert($scope.imgs.paths);
				}
				else
				{
					if(typeof($scope.cml)!="undefined")
					{
						replyid=$scope.cml.id;
					}
					//评论或者回复
					var _link=buildUrl('json','community','saveComment',{
						qid:document.getElementById('qid').value,
						uId:document.getElementById('uid').value,
						sId:$scope.ct.sid,
						comment:$scope._comment,
						replyId:replyid
					})
				}
//				$scope.uiObj.pageloadingCtrl=false;
				$scope.uiObj.layerloadingCtrl=true;
				if($scope._comment==''||typeof($scope._comment)=="undefined")
				{
					layer.open({
						content:'请输入内容'
					})
				}
				else
				{
					$http.get(_link).success(function(data){
					console.log(data);
						if(data.code==0)
						{
							if(replyid!='')
							{
								var _index=$scope.$parent.$index
							}
							else
							{
								var _index=$scope.$index
							}
							if(!$scope.isTie)
							{
								//更新并初始化 包含callSuccessHttp
								$scope.pageUi.updateList(_index);
							}
							else
							{
								$scope.callSuccessHttp();
								layer.open({
									content:'发帖成功~',
									time:2
								})
								location.reload();
							}
						}
						else
						{
							layer.open({
								content:data.msg
							})
						}
						//清空内容
						$scope._comment='';
					});
				}
			}
			this.putface=function(mark){
				console.log($scope);
				if(typeof($scope._comment)=="undefined")
				{
					$scope._comment="";
				}
				$scope._comment=$scope._comment+mark;
			};
		},
		link:function(s,e,a,c){
		}
	}
})
//注入表情
app.directive('sqFace',function(){
	return {
		require:'^sqMychat',
		controller:function($scope,$http){
			//返回mark
			$scope.getmark=function(){
				return $scope.g.mark;
			}
		},
		link:function(s,e,a,c){
			e.on('click',function(event){
//				event.preventDefault();
				var mark=s.getmark();
				c.putface(mark);
			})
		}
	}
})
app.directive('sqForm',["$timeout",function($timeout){
	return {
		link:function(s,e,a,c){
			if(!s.isTie)
			{
			 $timeout(function(){
                e[0].focus();
             })
			}
		}
	}
}])
app.directive('goArticle',function(){
	return {
		controller:function($scope,$http){
			this.goarticle=function(){
				console.log($scope);
				var _qId=document.getElementById('qid').value,_id,_miUId,type;
				_miUId=document.getElementById('miUId').value;
				if($scope.cl)
				{
					type=$scope.cl.type;
					_id=$scope.cl.id;
				}
				else
				{
					type=$scope.ct.type;
					_id=$scope.ct.id;
				}
				if(type==0||type==null)
				{
					var _link=buildUrl('html','micontent','getMiContentDetail',{
						qId:_qId,
						id:_id,
						miUId:_miUId
					})
					window.location.href=serhost+_link;
				}
			}
		},
		link:function(s,e,a,c){
			e.on('click',function(){
				c.goarticle();
			})
		}
	}
})
//我的用户，选择筛选 遮罩控制
app.directive('selectMask',function(){
	return {
		controller:function($scope,$http){
			$scope.hideMask=function(){
				$scope.pageUi.mask='sq-hide';
				for(var i=0;i<$scope.pageUi.content.length;i++)
				{
					$scope.pageUi.content[i].selectNav="sq-hide";
				}
			}
		}
	}
})
//我的用户，选择筛选交互
app.directive('sqSelectbtn',function(){
	return {
		controller:function($scope,$http){
			
			if($scope.pageUi.dataType==0)
			{
				var a=getCookie('extension');
				if(a!=null)
				{
					a=a.split(',');
					console.log(a);
					if(a[$scope.$index]=='')
					{
						a[$scope.$index]=0;
					}
					
//					$scope.pageUi.content[$scope.$index].name=$scope.s.list[$scope.s.activeselect].name;
					
					$scope.s.activeselect=a[$scope.$index];
					
				}
				else
				{
					$scope.s.activeselect=$scope.pageUi.activeselect;
				}
			}
			else
			{
				var a=getCookie('bulproduct');
				if(a!=null)
				{
					a=a.split(',');
					console.log(a);
					if(a[$scope.$index]=='')
					{
						a[$scope.$index]=0;
					}
					
//					$scope.pageUi.content[$scope.$index].name=$scope.s.list[$scope.s.activeselect].name;
					
					$scope.s.activeselect=a[$scope.$index];
					
				}
				else
				{
					$scope.s.activeselect=$scope.pageUi.activeselect;
				}
			}
//			$scope.s.activeselect=$scope.pageUi.activeselect;
			$scope.allSelectHide=function(){
				for(var i=0;i<$scope.pageUi.content.length;i++)
				{
					$scope.pageUi.content[i].selectNav="sq-hide";
				}
			}
			$scope.select=function(){
				if($scope.s.selectNav=="sq-hide")
				{
					$scope.allSelectHide();
					$scope.s.selectNav="sq-active";
					$scope.pageUi.mask='sq-active';
				}
				else
				{
					$scope.s.selectNav="sq-hide";
					$scope.pageUi.mask='sq-hide';
				}
			}
		}
	}
})
//分销商品--查看商品(返利)
app.directive('goprodetail',function(){
	return {
		controller:function($scope){
			$scope.goprodetail=function(){
				var _link=buildUrl('html','product','getProduct',{
					id:$scope.l.id,
					qId:document.getElementById('qid').value,
					sId:$scope.l.sId,
					miUId:document.getElementById('miUId').value,
					
				},$scope.l.fromCustomerId)
				window.location.href=_link;
			}
		}
	}
})

//邀请-用户列表分页
app.directive('refereePage',["$rootScope",function($rootScope){
	return {
		controller:function($scope,$http){
			this.getlist=function(){
				if($scope.pageUi.iswork)
				{
					$scope.pageUi.text='正在加载..';
					var _link=buildUrl('json','community','refereeInfo',{
						qid:document.getElementById('qid').value,
						start:$scope.pageUi.start,
						limit:$scope.pageUi.limit
					})
					$http.get(_link).success(function(response){
						if(response.refereeList!=null)
						{
							
							if($scope.pageUi.data!=null)
							{
								if(typeof($scope.pageUi.data.refereeList)!="undefined")
								{
									for(var i=0;i<response.refereeList.length;i++)
									{
											
										$scope.pageUi.data.refereeList.push(response.refereeList[i]);
									}
								}
							}
							//第一次
							else
							{
								
								$scope.pageUi.data=response;
								
							}
							console.log(response)
							
							$scope.pageUi.start=$scope.pageUi.start+$scope.pageUi.limit;
							if(response.refereeList.length<$scope.pageUi.limit)
							{
								$scope.pageUi.iswork=false;
								$scope.pageUi.text='无更多数据';
							}
							else
							{
								$scope.pageUi.text='下拉加载更多';
							}
						}
						else
						{
							//quanInfo也要导入
							$scope.pageUi.data=response;
							$scope.pageUi.iswork=false;
							$scope.pageUi.text='无更多数据';
						}
						if(!$scope.pageUi.isShare)
						{
							$scope.pageUi.isShare=true;
//							shareData.link=response.quanInfo.refereeUrl;
//							wx_share.init(shareData);
						}
						
						$scope.callSuccessHttp();
					});
					
				}
			}
		},
		link:function(s,e,a,c){
			
			c.getlist();
			window.onscroll = function(){
				if(getScrollTop() + getWindowHeight() == getScrollHeight()&&getScrollTop()!=0)
				{
					c.getlist();
				}
			}
		}
	}
}])
//我的用户，选择筛选
app.directive('sqSelectIn',["$rootScope",function($rootScope){
	return {
		controller:function($scope,$http){
			var _this=this;
			if($scope.$parent.$index==0)
			{
				var f_cid=$scope.v.customerId;
			}
			
//			if($scope.$last)
//			{
//				
//				alert($scope.s.activeselect);
//			}

			$scope.s.name=$scope.s.list[$scope.s.activeselect].name;
			
	
			$scope.selectIn=function(){
				
				if($scope.pageUi.dataType==0)
				{
					if(typeof($scope.v.customerId)!="undefined")
					{
						$scope.pageUi.cid=$scope.v.customerId;
					}
					if(typeof($scope.v.type)!="undefined")
					{
						$scope.pageUi.type=$scope.v.type;
					}
				}
				else
				{
					//商品分销供应商选择
					if($scope.$parent.$index==0)
					{
						$scope.pageUi.vid=$scope.v.id;
						$scope.pageUi.tagId='';
						$scope._params.tagId='';
						$scope.pageUi.selectinit=true;
						$scope.pageUi.content[1].name="商品分类";
						$scope.uiObj.layerloadingCtrl=true;
					}
					else if($scope.$parent.$index==1)
					{
						$scope.pageUi.tagId=$scope.v.id;
						$scope.pageUi.selectinit=false;
					}
					else if($scope.$parent.$index==2)
					{
						$scope.pageUi.sort=$scope.v.type;
					}
				}
				$scope.s.activeselect=$scope.$index;
				$scope.s.name=$scope.v.name;
				
				
				if($scope.pageUi.dataType!=0)
				{
					if($scope.$parent.$index==0)
					{
						bulselectlist[1]=0;
					}
					
					bulselectlist[$scope.$parent.$index]=$scope.s.activeselect;
					
					
					bulselectstr='';
					for(var i=0;i<bulselectlist.length;i++)
					{
						if(i!=0)
						{
							tmp=',';
						}
						else
						{
							tmp='';
						}
						bulselectstr=bulselectstr+tmp+bulselectlist[i];
					}
					setCookie('bulproduct',bulselectstr,'d30');
				}
				else
				{
					exselectlist[$scope.$parent.$index]=$scope.s.activeselect;
					
					exselectstr='';
					for(var i=0;i<exselectlist.length;i++)
					{
						if(i!=0)
						{
							tmp=',';
						}
						else
						{
							tmp='';
						}
						exselectstr=exselectstr+tmp+exselectlist[i];
					}
					setCookie('extension',exselectstr,'d30');
				}
				
				
				
				
				//http部分
				$scope.pageUi.isSelect=true;
				_this.getlist();
//				console.log("cid:"+$scope.pageUi.cid+',type:'+$scope.pageUi.type+',vid:'+$scope.pageUi.vid+',tagId:'+$scope.pageUi.tagId+',sort:'+$scope.pageUi.sort)
			}
			this.getlist=function(){
				console.log($scope._params);
				if($scope.pageUi.isSelect)
				{
					$scope.pageUi.data='';
					$scope.pageUi.init();
					//若操作筛选时，选择参数为操作过的那个值优先
					if($scope.pageUi.cid!=null)
					{
						$scope._params.cid=$scope.pageUi.cid
					}
					if($scope.pageUi.type!=null)
					{
						$scope._params.type=$scope.pageUi.type
					}
					if($scope.pageUi.vid!=null)
					{
						$scope._params.vid=$scope.pageUi.vid
					}
					
					if($scope.pageUi.tagId!=null)
					{
						$scope._params.tagId=$scope.pageUi.tagId
					}
					
					if($scope.pageUi.sort!=null)
					{
						$scope._params.sort=$scope.pageUi.sort
					}
					$scope.pageUi.isSelect=false;
				}
				else
				{
					//若没发生操作,则缓存里的参数优先.
					$scope._params.cid=((getCookie('cid')=="null"||getCookie('cid')==null)?f_cid:getCookie('cid'));
					$scope._params.type=(getCookie('type')=="null"?null:getCookie('type'));
					$scope._params.vid=(getCookie('vid')=="null"?null:getCookie('vid'));
					$scope._params.tagId=(getCookie('tagId')=="null"?null:getCookie('tagId'));
					$scope._params.sort=(getCookie('sort')=="null"?null:getCookie('sort'));
				}
				if($scope.pageUi.dataType==0)
				{
					var _link=buildUrl('json','community','recruitUserList',{
						qid:document.getElementById('qid').value,
						cid:$scope._params.cid!=null?$scope._params.cid:'',
						type:$scope._params.type!=null?$scope._params.type:0,
						start:$scope.pageUi.start,
						limit:$scope.pageUi.limit
					})
					
					//最终发生请求时,将最终值存入缓存中.
					setCookie('cid',$scope._params.cid,'d30');
					setCookie('type',$scope._params.type,'d30');
				}
				else
				{

					
					var _link=buildUrl('json','community','getProductByCondition',{
						qid:document.getElementById('qid').value,
						vid:$scope._params.vid!=null?$scope._params.vid:'',
						tagId:$scope._params.tagId!=null?$scope._params.tagId:'',
						sort:$scope._params.sort!=null?$scope._params.sort:0,
						start:$scope.pageUi.start,
						limit:$scope.pageUi.limit
					})
					//最终发生请求时,将最终值存入缓存中.
					setCookie('vid',$scope._params.vid,'d30');
					setCookie('tagId',$scope._params.tagId,'d30');
					setCookie('sort',$scope._params.sort,'d30');
				}
				console.log('cid:'+$scope._params.cid+',type:'+$scope._params.type+',vid:'+$scope._params.vid+',tagId:'+$scope._params.tagId+',sort:'+$scope._params.sort)
				console.log('cid:'+getCookie('cid')+',type:'+getCookie('type')+',vid:'+getCookie('vid')+',tagId:'+getCookie('tagId')+',sort:'+getCookie('sort'))
//				$scope.uiObj.pageloadingCtrl=false;
				if($scope.pageUi.isWork){
					$scope.pageUi.text='正在加载...';
					$scope.pageUi.mallload=true;
					$http.get(_link).success(function(response){
						if(typeof(response.userList)!="undefined"||typeof(response.productList)!="undefined")
						{
							var KEY=typeof(response.userList)!="undefined"?"userList":"productList";
							//有数据
							if(response.userList!=null||response.productList!=null)
							{
															
								if($scope.pageUi.isFirst)
								{
									$scope.pageUi.data = response;
									$scope.pageUi.isFirst=false;
									if(response[KEY].length<$scope.pageUi.limit)
									{
										$scope.pageUi.isWork=false;
										$scope.pageUi.text='没有更多数据';
									}
								}
								else
								{
									for(var i=0;i<response[KEY].length;i++)
									{
										
										$scope.pageUi.data[KEY].push(response[KEY][i]);
									}
								}
								$scope.pageUi.start=$scope.pageUi.start+$scope.pageUi.limit;
								if($scope.pageUi.isWork)
								{
									$scope.pageUi.text='下拉加载';
								}
								
							}
							else
							{
								if($scope.pageUi.dataType==0&&$scope.pageUi.isFirst)
								{
									$scope.pageUi.data={
										count:'',
										mallUrl:''
									}
									$scope.pageUi.data.count = response.count;
									$scope.pageUi.data.mallUrl = response.mallUrl;
								}
								
								$scope.pageUi.isWork=false;
								$scope.pageUi.text='没有更多数据';
							}
						}
						else
						{
							$scope.pageUi.text='';
						}
						
						//选择供应商，分类列表需要更新distributionList,不管userList和productList是否值
							    if(KEY=="productList"&&$scope.$parent.$index==0&&$scope.pageUi.isSelect)
								{
									if(response.distributionList)
									{
										$scope.pageUi.content[1].list=response.distributionList;
									}
									else
									{
										$scope.pageUi.content[1].list=new Array();
									}
									$scope.pageUi.content[1].activeselect=0;
									$scope.pageUi.content[1].list.unshift({
										id:'',
										name:'全部',
										logo:1
									})
								}		
						$scope.pageUi.mallload=false;
						$scope.callSuccessHttp();
					});
				}
			}
		},
		link:function(s,e,a,c){
			if(s.$last&&s.$parent.$index==0)
			{
				c.getlist();
				//监听滚动条
				 window.onscroll = function()
				{
					s.pageUi.isSelect=false;
				　　  if(getScrollTop() + getWindowHeight() == getScrollHeight()&&getScrollTop()!=0)
					{
					　　　c.getlist();
					}
				}
			}
		}
	}
}])
app.directive('listenBlance',function(){
	return {
		controller:function($scope,$http,$cacheFactory,$routeParams){
			if($routeParams.type==0)
			{
				$scope.detailType=1;
			}
			else if($routeParams.type==1)
			{
				$scope.detailType=0;
			}
			$scope.showDetail=function(type){
				if(type==1)
				{
					$scope.detailType=0;
				}
				else if(type==0)
				{
					$scope.detailType=1;
				}
				
			}
			this.getmore=function(_tType){
				if($scope.detailType==0)
				{
					var dt=$scope.pageUi.balancelist[1];
				}
				else
				{
					var dt=$scope.pageUi.balancelist[0];
				}
				
				console.log(dt);
				if(dt.loadlist&&dt.iswork)
				{
					dt.loadlist=false;
					var _link=buildUrl('json','settlement','accountList',{
						id:document.getElementById('userid').value,
						agent:document.getElementById('agent').value,
						type:$scope.detailType,
						start:dt.start,
						limit:dt.limit
					})
					$http.get(_link).success(function(response){
						//有数据
						if(response!='null'&&response!='false')
						{
							
							for(var i=0;i<response.length;i++)
							{
								dt.balancelist.push(response[i]);
							}
							dt.start=dt.start+dt.limit;
							console.log($scope.pageUi.balancelist);
							
						}
						//无数据
						else
						{
							dt.iswork=false;
						}
						dt.loadlist=true;
						$scope.callSuccessHttp();
						
						
					})
				}
				
			}
		},
		link:function(s,e,a,c){
			window.onscroll = function()
			{
			    if(getScrollTop() + getWindowHeight() == getScrollHeight()&&getScrollTop()!=0)
				{
				    c.getmore();
				}
			}
				
		}
	}
})


//我的收入 明细列表
app.directive('balanceList',function(){
	return {
		controller:function($scope,$http){
			this.getlist=function(_tType){
			
				var _link=buildUrl('json','settlement','accountList',{
					id:document.getElementById('userid').value,
					agent:document.getElementById('agent').value,
					type:_tType,
					start:$scope.p.start,
					limit:$scope.p.limit
				})
				$scope.p.loadlist=false;
				$http.get(_link).success(function(response){
					console.log(response);
					$scope.p.loadlist=true;
					if(response!="null"&&response!='false')
					{
						$scope.p.balancelist=response;
					}
					else
					{
						$scope.p.iswork=false;
						$scope.p.balancelist=null;
					}
					
					$scope.p.start=$scope.p.start+$scope.p.limit;
					$scope.callSuccessHttp();
					
				})
				
				
			}
			
		},
		link:function(s,e,a,c){
			console.log(s);
			c.getlist(s.p.tType);
			
		}
	}
});


//下拉加载分页
app.directive('sqDropmoreajax',function(){
	return {
		controller:function($scope,$http){
			var _this=this;
			$scope.isloaded=true;
			this.getlist=function(){
				
//				alert('开始加载啦');
				var _link=buildUrl('json','community','contentList',{
					qid:document.getElementById('qid').value,
					start:$scope.pageUi.start-$scope.pageUi.isTopCount,
					limit:$scope.pageUi.limit
				})
//				$scope.uiObj.pageloadingCtrl=false;
				
				if($scope.pageUi.isWork&&$scope.isloaded)
				{
					$scope.pageUi.text='正在加载...';
					$scope.isloaded=false;
					$http.get(_link).success(function(response){
						if(response.content!=null)
						{
							if($scope.pageUi.isFirst)
							{
								
								$scope.data = response;
								$scope.pageUi.isFirst=false;
							}
							else
							{
								for(var i=0;i<response.content.length;i++)
								{
									$scope.data.content.push(response.content[i]);
								}
							}
							
							console.log($scope);
							$scope.pageUi.start=$scope.pageUi.start+$scope.pageUi.limit;
							$scope.pageUi.text='下拉加载';
						}
						else
						{
							$scope.pageUi.text='没有更多数据';
							$scope.pageUi.isWork=false;
						}
						$scope.isloaded=true;
						$scope.callSuccessHttp();
					});
				}
			}
		},
		link:function(s,e,a,c){			
			c.getlist();
			//添加点击加载更多
			e.find('.sq-dropmore').on('click',function(){
				c.getlist();
			})
			//监听滚动条
			 window.onscroll = function()
			{
			　　  if(getScrollTop() + getWindowHeight() == getScrollHeight()&&getScrollTop()!=0)
				{
				　　　　c.getlist();
				}
			}
		}
	}
})

